package util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @Author: 陈艺博
 * @Date: 2020-05-04 22:15
 * @Description: 运行时间测试
 */
public class ConsumeTimesUtil {	private static final SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss.SSS");

    public interface Task {
        void execute();
    }

    public static void test(String title, Task task) {
        if (task == null) return;
        title = (title == null) ? "" : ("【" + title + "】");
        System.out.println(title);
        System.out.println("开始：" + fmt.format(new Date()));
        long begin = System.currentTimeMillis();
        task.execute();//这里相当于运行传入的方法
        long end = System.currentTimeMillis();
        System.out.println("结束：" + fmt.format(new Date()));
        double delta = (end - begin);
        System.out.println("耗时： " + delta + " ms");
        System.out.println("-------------------------------------");
    }
}
